package com.aaa.service.impl.scl;

import com.aaa.entity.MyPage;

import com.aaa.entity.mht.MhtQuestion;
import com.aaa.entity.scl.TsclQuestion;
import com.aaa.mapper.scl.TsclQuestionMapper;
import com.aaa.service.scl.TsclQuestionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
public class TsclQuestionServiceImpl implements TsclQuestionService {
    @Autowired
    private TsclQuestionMapper tsclMapper;

    /**
     * 导入excel数据
     * @param
     * @return
     */
    @Override
    public Boolean inductsExcelFile(List<Object> list) {
        int i=-1;
        for (Object excelList: list) {
            TsclQuestion excelList1 = (TsclQuestion) excelList;
            int insert = tsclMapper.insert(excelList1);
            i+=insert;
        }
        return i>=0;
    }

    /**
     * 查询题目信息
     * @return
     */
    @Override
    public PageInfo selectAll(MyPage myPage,TsclQuestion tsclQuestion) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        List<TsclQuestion> allQuestion = tsclMapper.findAllQuestion(tsclQuestion);
        List<TsclQuestion> questions = tsclMapper.selectAll();
        PageInfo pageInfo = new PageInfo(allQuestion);
        return pageInfo;

    }
    /**
     * 添加题目
     */
    @Override
    public Boolean addSCL(TsclQuestion tscl) {;
        int i=-1;
        Integer id = tscl.getId();
        if(id==null){
            i = tsclMapper.insertSelective(tscl);
        }else {
            i=tsclMapper.updateByPrimaryKeySelective(tscl);
        }
        return i>0?true:false;
    }
    /**
     * 删除题目
     * @param tscl
     * @return
     */
    @Override
    public Boolean delSCL(TsclQuestion tscl) {
        int delete = tsclMapper.deleteByPrimaryKey(tscl);
        if(delete>=0){
            return true;
        }
        return false;
    }

    /**
     * 检测题目是否存在
     */
    @Override
    public Boolean checkQId(Integer qid) {

        TsclQuestion tsclQuestion=new TsclQuestion();
        tsclQuestion.setQid(qid);
        TsclQuestion tsclQuestion1 = tsclMapper.selectOne(tsclQuestion);
        if(tsclQuestion1!=null){
            return true;
        }else {
            return false;
        }

    }
}
